<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ～ ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\customs\excel;

use catchAdmin\customs\model\Order as OrderModel;
use catcher\library\excel\ExcelContract;
use PhpOffice\PhpSpreadsheet\Style\Alignment;

class clearOrderExport implements ExcelContract
{
    protected $orderModel;

    /**
     *
     * @time 2021/11/03 14:02
     * @param OrderModel $orderModel
     * @param OrderSonModel $OrderSonModel
     * @return mixed
     */
    public function __construct(OrderModel $orderModel)
    {
        $this->orderModel = $orderModel;
    }
    /**
     * 设置头部
     *
     * @time 2020年09月08日
     * @return string[]
     */
    public function headers(): array
    {
        // TODO: Implement headers() method.
        return [
            '订单号', '订单时间', '订购人', '订单金额', '清单状态','清单编号' , '放行时间'
        ];
    }
    /**
     * 设置行宽
     *
     * @time 2020年09月08日
     * @return int
     */
    public function setWidth()
    {
        return [
            "A"=>15, "B"=>20, "C"=>15, "D"=>15, "E"=>20, "F"=>25, "G"=>20
        ];
    }
    public function getPushInventoryAttr($value)
    {
        $status = [0=>'未推送',1=>'电子口岸已暂存',2=>'电子口岸申报中',3=>'发送海关成功',4=>'发送海关失败',100=>'海关退单',120=>'海关入库', 300=>'人工审核',399=>'海关审结',800=>'放行',899=>'结关',500=>'查验',501=>'扣留移送通关',502=>'扣留移送缉私',503=>'扣留移送法规',599=>'其它扣留',700=>'退运'];

        return array_key_exists($value,$status)?$status[$value]:$value;
    }

    /**
     * 处理数据
     *
     * @time 2020年09月08日
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @return \think\Collection
     */
    public function sheets()
    {
        $list = $this->orderModel->getClearExportList();
        foreach ($list as $key => &$value){
            if($value->push_inventory === 800){
                $value->completeDateTime = date('Y-m-d H:i:s',strtotime($value->completeDateTime));
            }else{
                $value->invt_no = "";
                $value->completeDateTime = "";
            }
            $value->orderId .= "\t";
            $value->ConsigneeCode .= "\t";
            $value->push_inventory = $this->getPushInventoryAttr($value->push_inventory);
        }
        return $list;
    }

    /**
     * 设置开始行
     *
     * @time 2020年09月08日
     * @return int
     */
    public function setRow()
    {
        return 2;
    }


    /**
     * 设置标题
     *
     * @time 2020年09月08日
     * @return array
     */
    public function setTitle()
    {
        return [
            'A1:G1', '导出清单', Alignment::HORIZONTAL_CENTER
        ];
    }
}